package org.transfer.service;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.transfer.utils.ConfigUtil;
import org.transfer.utils.FileUtils;

/**
 * 定时删除遗留的log日志文件
 * 
 * @author kuan
 *
 */
public class DeleteLogFileService {

	public static void init() {
		try {
			String period = ConfigUtil.getConfigure().getProperty("del_period");
			String time = ConfigUtil.getConfigure().getProperty("del_time");

			String decryptPath = ConfigUtil.getConfigure().getProperty("decryptPath");
			String decryptOutPath = ConfigUtil.getConfigure().getProperty("decryptOutPath");
			String decompressionOutPath = ConfigUtil.getConfigure().getProperty("decompressionOutPath");

			Runnable runnable = new Runnable() {
				public void run() {
					try {
						long start = System.currentTimeMillis();
						FileUtils.deleteDirectory(decryptPath);
						FileUtils.deleteDirectory(decryptOutPath);
						FileUtils.deleteDirectory(decompressionOutPath);
						long end = System.currentTimeMillis();
						System.out.println("删除日志-执行时间：" + (end - start));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
			// 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
			service.scheduleAtFixedRate(runnable, Integer.valueOf(period), Integer.valueOf(period),
					TimeUnit.valueOf(time));
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

}
